import { showFailToast } from "../utils";
import { uniFetch } from "./uni-fetch";

export function loginRequest(formData,callback){
  if(!formData.account || !formData.password){
    showFailToast('登录参数为空')
    return
  }
  uniFetch.post('/driver/login/account',{account:formData.account,
                password:formData.password})
          .then(res => {
            callback(res.data)
          }).catch(err => {
      showFailToast('发生异常' + JSON.stringify(err))
    })
}
export function getLoginUser(callback){
  uniFetch.get('/driver/users').then(res => {

      if(res.statusCode === 200){
        callback(res.data.data)
      }else{
        showFailToast('未登录')
        uni.navigateTo({
          url:'/pages/login/index'
        })
      }
    }).catch(err => {
      showFailToast('发生异常' + JSON.stringify(err))
    })
}

//获取我的任务数据
export function getMyTask(year,month,callback){
  return uniFetch.get('/driver/users/taskReport',{year,month}).then(res => {
    if(callback){
      callback(res.data)
    }
  }).catch(err => {
      showFailToast('发生异常' + JSON.stringify(err))
    })
}

//获取车辆信息
export function getTruckRequest(callback){
  return uniFetch.get('/driver/users/truck').then(res => {
    if(callback){
      callback(res.data)
    }
  }).catch(err => {
      showFailToast('发生异常' + JSON.stringify(err))
    })
}
